// ===============================================================================================
// VOLUSION HELP - TOOLTIPS - BEGIN
// ===============================================================================================
// ------------------------------------------------------
var previous_click_image_obj = new Image();
// ------------------------------------------------------		
var tipwidth='500px' //default tooltip width (NOT USED!, passed into function instead)
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="0px" //horizontal offset of tooltip from anchor link
var horizontal_offset="0px" //horizontal offset of tooltip from anchor link
// ------------------------------------------------------
var ie4=document.all
var ns6=document.getElementById&&!document.all
if (ie4||ns6) {
	// OLD LINE WAS: document.write('<div id="VolusionHelpToolTip" style="visibility:hidden;width:'+tipwidth+'" ></div>')
	document.write('<div id="VolusionHelpToolTip" style="visibility:hidden; width:' + tipwidth + '; position:absolute; padding:4px;z-index:1000;"></div>');
document.write('<iframe id="DivShim" src="../blank.html" scrolling="no" frameborder="0" style="display:none; left:0px; position:absolute; TOP:0px"></iframe>');

}
// ------------------------------------------------------
function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}
// ------------------------------------------------------
function showhide(obj, e, visible, hidden, tipwidth){
	if (ie4||ns6)
	dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (tipwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=tipwidth
	}
	//if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
	obj.visibility=visible
	//else if (e.type=="click")
	//obj.visibility=hidden
}
// ------------------------------------------------------
function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
// ------------------------------------------------------
function clearbrowseredge(obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
	var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
	dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
	edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
	var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
	edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	}
	return edgeoffset
}

//module-wide variable to store "off" image
var offimg = '';

// ------------------------------------------------------
function fixedtooltip(current_click_image_obj, table_dot_field, store_version, obj, e, tipwidth, righORleft, missingFields, Language) {

    //2010-04-09: 774:
    if (offimg == '') {
        offimg = current_click_image_obj.src; 
    }

    //2010-04-09: 774:
    if (fixedtooltip_saved_current_click_image_obj && previous_click_image_obj) {
        fixedtooltip_saved_current_click_image_obj.src = previous_click_image_obj.src;
    }

    //2010-04-09: 774:
    if (fixedtooltip_saved_current_click_image_obj == current_click_image_obj) {
        fixedtooltip_saved_current_click_image_obj.src = offimg;
        fixedtooltip_saved_current_click_image_obj = null;
        hidetip();
        return;
    }
    
    
	//save the variables for later use...
	if (!fixedtooltip_saved_current_click_image_obj || current_click_image_obj) {
		fixedtooltip_saved_current_click_image_obj = current_click_image_obj;
	}
	fixedtooltip_saved_table_dot_field = table_dot_field;
	fixedtooltip_saved_obj = obj;
	fixedtooltip_saved_e = e;
	fixedtooltip_saved_tipwidth = tipwidth;
	fixedtooltip_saved_righORleft = righORleft;


	// Use AJAX to get help contents, then when the reply comes back it will then call part2...
	if (!missingFields)
		missingFields = '';
	if (!Language)
		Language = '';
		
		
	askClearHelp(fixedtooltip_saved_current_click_image_obj.id,table_dot_field,store_version,missingFields,Language);
	
}
// ------------------------------------------------------
function fixedtooltip_part2(menucontents){

    //alert(menucontents);
    
	//load cached variables...
	var current_click_image_obj = fixedtooltip_saved_current_click_image_obj;
	var table_dot_field = fixedtooltip_saved_table_dot_field;
	var obj = fixedtooltip_saved_obj;
	var e = fixedtooltip_saved_e;
	var tipwidth = fixedtooltip_saved_tipwidth;
	var righORleft = fixedtooltip_saved_righORleft;

	//2010-04-09: 774
	if (menucontents == '') {
	    fixedtooltip_saved_current_click_image_obj = null;
	}
	
	// ------------------------------------------------------
	var IfrRef = document.getElementById('DivShim');
	IfrRef.style.display = "none";
	// ------------------------------------------------------
	
	if (current_click_image_obj.src.substring(current_click_image_obj.src.length-8) == "_off.png") {
		current_click_image_obj.src = previous_click_image_obj.src;	
		hidetip();
		clearhidetip();
	} else {
		
		try{
		KBTracker._trackEvent('Click - link','Instant Help : ' + table_dot_field,1);
		}catch(err){}
		
		previous_click_image_obj.src = current_click_image_obj.src;
		//current_click_image_obj.src = "/a/a/i/icon_postit_over.gif";
		current_click_image_obj.src = "/a/a/65/i/help_icon_off.png";//"/a/i/adminimages/icon_help_over.gif";
		if (window.event) event.cancelBubble=true
		else if (e.stopPropagation) e.stopPropagation()
		dropmenuobj=document.getElementById? document.getElementById("VolusionHelpToolTip") : VolusionHelpToolTip
		dropmenuobj.innerHTML = menucontents;
		//New styling - F10
		$("#VolusionHelpToolTip").children().wrap("<div class=\"tooltipLeft\"><div class=\"tooltipRight\"><div class=\"tooltipMain\"></div></div></div>");
		$("#VolusionHelpToolTip").prepend("<div class=\"tooltipHeader\"><div class=\"tooltipHeader_Left\"></div><div class=\"tooltipHeader_Main\" style=\"width:" + (tipwidth.replace("px", "") - 128) + "px;\"></div><div class=\"tooltipHeader_Right\"></div></div>");
		$("#VolusionHelpToolTip").append("<div class=\"tooltipFooter\"><div class=\"tooltipFooter_Left\"></div><div class=\"tooltipFooter_Main\" style=\"width:" + (tipwidth.replace("px", "") - 128) + "px;\"></div><div class=\"tooltipFooter_Right\"></div></div>");
//		if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
		var tooltipPlacement = vPlacement(obj);
		//New styling - F10
		dropmenuobj.x=tooltipPlacement.left;
		dropmenuobj.y=tooltipPlacement.top;// + 3;

		
		// Make sure not off side of screen  
		if(dropmenuobj.x < 0) {
		   dropmenuobj.x = 10;
		  }

        //2010-04-09: 774
		dropmenuobj.x += 20;
		dropmenuobj.y += 5;
		
		//2010-06-28: 968
		dropmenuobj.style.left = dropmenuobj.x + "px";
		
		if (clearbrowseredge(obj, "rightedge") < dropmenuobj.x) {
			dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + "px";
		}
		
		//New styling for F10
		if (dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight < 0) {
			dropmenuobj.style.top = dropmenuobj.y + "px";
		}
		else {
			dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + "px";
		}
		var toolTipDirection = "";
		var toolTipOffset = $("#VolusionHelpToolTip").offset();
		if (dropmenuobj.y - 6 < toolTipOffset.top) {
			toolTipDirection = "Header";
			toolTipOffset.top = toolTipOffset.top - 29;
		}
		else {
			toolTipDirection = "Footer";
			toolTipOffset.top = toolTipOffset.top + 10;
		}
		if (dropmenuobj.x - 6 < toolTipOffset.left) {
			toolTipDirection += "_Left";
			toolTipOffset.left = toolTipOffset.left - 38;
		}
		else {
			toolTipDirection += "_Right";
			toolTipOffset.left = toolTipOffset.left - 8;
		}
		$("#VolusionHelpToolTip").offset({ top: toolTipOffset.top, left: toolTipOffset.left });
		$("#VolusionHelpToolTip .tooltip" + toolTipDirection).addClass("tooltipCallout");
			// ------------------------------------------------------
			// Iframe Trick to get over SELECT boxes
			// ------------------------------------------------------
            //2010-04-09: 774            if (document.all && IEVersion < 8) {
			    var DivRef = document.getElementById('VolusionHelpToolTip');
			    IfrRef.style.width = DivRef.offsetWidth;
			    IfrRef.style.height = DivRef.offsetHeight;
			    IfrRef.style.left = (dropmenuobj.style.left);
			    IfrRef.style.top = (dropmenuobj.style.top);
			    IfrRef.style.zIndex = 99; //must be one behind the VolusionHelpToolTip popup
			    IfrRef.style.visibility = "visible";
			    IfrRef.style.display = "block";
			}
			
			// ------------------------------------------------------

	}
}
// ------------------------------------------------------
function hidetip(e){
if (typeof dropmenuobj!="undefined"){
//	if (ie4||ns6)
	dropmenuobj.style.visibility="hidden"
	}
}
// ------------------------------------------------------
function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}
// ------------------------------------------------------
function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
// ------------------------------------------------------
function handleHttpResponse() {
  if (http.readyState == 4) {
	if (http.status == 200) {
		// Return the value and continue the function part2...
		fixedtooltip_part2(http.responseText);
		isWorking = false;
	} else {
		alert("There was a problem retrieving the XML data:\n" +
		http.statusText);
    }
  }
}
function askClearHelp(arg_image_id,arg_table_dot_field,arg_store_version,arg_missingFields,arg_Language) {
  if (!isWorking && http) {
      var zipValue = ""; //document.getElementById("zip").value;
      
      //document.write("../volusion_help_tooltips.asp?image_id=" + arg_image_id + "&table_dot_field=" + escape(arg_table_dot_field) + "&store_version=" + escape(arg_store_version) + "&missing_fields=" + escape(arg_missingFields) + "&Language=" + escape(arg_Language));
      
	http.open("GET", "../volusion_help_tooltips.asp?image_id=" + arg_image_id + "&table_dot_field=" + escape(arg_table_dot_field) + "&store_version=" + escape(arg_store_version) + "&missing_fields=" + escape(arg_missingFields) + "&Language=" + escape(arg_Language), true);
    http.onreadystatechange = handleHttpResponse;
    isWorking = true;
//	if (window.XMLHttpRequest) {
	    http.send(null); // mozilla + safari
//	} else if (window.ActiveXObject) {
//		http.send(""); // ie
//	}
  }
}
var fixedtooltip_saved_current_click_image_obj;
var fixedtooltip_saved_table_dot_field;
var fixedtooltip_saved_obj;
var fixedtooltip_saved_e;
var fixedtooltip_saved_tipwidth;
var fixedtooltip_saved_righORleft;
var isWorking = false;
/* Create a new XMLHttpRequest object to talk to the Web server */
var http = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    http = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    http = false;
  }
}
@end @*/

if (!http && typeof XMLHttpRequest != 'undefined') {
  http = new XMLHttpRequest();
}

// ------------------------------------------------------
// ===============================================================================================
// VOLUSION HELP - TOOLTIPS - END
// ===============================================================================================

function ToggleLegend(showHide,objName,obj){
			
	if(showHide==true){
		v$(objName).style['display']='block';
		v$(objName).style['position']='absolute';
		
		var tooltipPlacement = vPlacement(obj);
		
		
		v$(objName).x=tooltipPlacement.left;// - 200;
		v$(objName).y=tooltipPlacement.top;// + 3;
		
		if(v$(objName).x < 0) {
		   v$(objName).x = 10;
		}
		
		v$(objName).style.left=v$(objName).x-clearbrowseredgeAlt(v$(objName), obj, "rightedge")+"px"
		if (v$(objName).y-clearbrowseredgeAlt(v$(objName), obj, "bottomedge")+obj.offsetHeight < 0){
			v$(objName).style.top = '10px';
		}else{
			v$(objName).style.top=v$(objName).y-clearbrowseredgeAlt(v$(objName), obj, "bottomedge")+obj.offsetHeight+"px";
		}
	}else{
		v$(objName).style['display']='none';
	}

}
function clearbrowseredgeAlt(floatobj, obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
	var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
	floatobj.contentmeasure=floatobj.offsetWidth
	if (windowedge-floatobj.x < floatobj.contentmeasure)
	edgeoffset=floatobj.contentmeasure-obj.offsetWidth
	}
	else{
	var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	floatobj.contentmeasure=floatobj.offsetHeight
	if (windowedge-floatobj.y < floatobj.contentmeasure)
	edgeoffset=floatobj.contentmeasure+obj.offsetHeight
	}
	return edgeoffset
}
